#include "NARFModel.h"

#include "core/AppDirectory.h"

namespace {
const QString UserFilename = "pcl.narf_model.json";
}

NARFModel::NARFModel()
    : BasePclModel()
{
    setPclHelpPage("https://pcl.readthedocs.io/projects/tutorials/en/master/narf_feature_extraction.html");
}

NARFModel& NARFModel::get()
{
    static NARFModel instance;
    if (instance.filename().isEmpty()) {
        instance.setFilename(AppDirectory::get().getAppDocFile(UserFilename));
        instance.load();
    }
    return instance;
}

void NARFModel::fromJson(const QJsonObject& json, QStringList& errorList)
{
    BasePclModel::fromJson(json, errorList);

    pcdFile_ = json["pcdFile"].toString(pcdFile_);
    farRangesPcdFile_ = json["farRangesPcdFile"].toString();
    angularResolution_ = json["angularResolution"].toDouble();
    supportSize_ = json["supportSize"].toDouble();
    coordinateFrame_ = static_cast<pcl::RangeImage::CoordinateFrame>(json["coordinateFrame"].toInt());
    setUnseenToMaxRange_ = json["setUnseenToMaxRange"].toBool();
    rotationInvariant_ = json["rotationInvariant"].toBool();
}

QJsonObject NARFModel::toJson() const
{
    QJsonObject json = BasePclModel::toJson();

    json["pcdFile"] = pcdFile_;
    json["farRangesPcdFile"] = farRangesPcdFile_;
    json["angularResolution"] = angularResolution_;
    json["supportSize"] = supportSize_;
    json["coordinateFrame"] = static_cast<int>(coordinateFrame_);
    json["setUnseenToMaxRange"] = setUnseenToMaxRange_;
    json["rotationInvariant"] = rotationInvariant_;
    return json;
}
